package com.TPNexus;

import javax.enterprise.context.SessionScoped;
import javax.faces.context.FacesContext;
import javax.inject.Inject;
import javax.inject.Named;
import javax.servlet.http.HttpServletRequest;

import com.TPNexus.dao.PurchaseOrderDAO;
import com.TPNexus.model.PurchaseOrder;
import com.TPNexus.model.PurchaseOrderLineItem;

import java.io.Serializable;
import java.util.ArrayList;

@Named
@SessionScoped
public class PurchaseOrderPagesController implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	@Inject
	private PurchaseOrderDAO podao;
	//member variable
	private PurchaseOrder po;
	private PurchaseOrderLineItem poli;
	
	//getter and setter
	public PurchaseOrder getPo() {
		return po;
	}

	public void setPo(PurchaseOrder po) {
		this.po = po;
	}

	public PurchaseOrderLineItem getPoli() {
		return poli;
	}

	public void setPoli(PurchaseOrderLineItem poli) {
		this.poli = poli;
	}
	
    //load purchase order list buyer
	public ArrayList<PurchaseOrder>getNewPOListBuyerView(){
		return podao.getPOListBuyerView(1, "NEW");
	}
	
	public ArrayList<PurchaseOrder>getAcceptedPOListBuyerView(){
		return podao.getPOListBuyerView(1, "ACCEPTED");
	}
	
	public ArrayList<PurchaseOrder>getRejectedPOListBuyerView(){
		return podao.getPOListBuyerView(1, "REJECTED");
	}
	
	//load purchase order list seller
	public ArrayList<PurchaseOrder>getNewPOListSellerView(){
		return podao.getPOListBuyerView(1, "NEW");
	}
	
	//
	public String getPODetailById(){
		HttpServletRequest request = (HttpServletRequest) FacesContext
				.getCurrentInstance().getExternalContext().getRequest();
		Integer id = Integer.parseInt(request.getParameter("id"));
		po=podao.getPODetailById(id);
		return "PurchaseOrderDetailBuyerView";
	}

}
